{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% block title %}Organization Applications{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item active">Organization Applications</li>
{% endblock %}

{% block content %}
<div class="card">
  <div class="card-body">
    <form>
      <div class="input-group input-group-lg">
        <input id="q" name="q" type="text" class="form-control input-lg" placeholder="Search"{% if query %} value="{{ query }}"{% endif %} aria-describedby="qHelpBlock">
        <div class="input-group-btn input-group-append">
          <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </div>
      </div>
      <div id="qHelpBlock" class="help-block no-margin">
        Examples: word "whole phrase"
        <a href="#" data-input="q" data-append="name:">name:</a>psf
        <a href="#" data-input="q" data-append="organization:">org:</a>python
        <a href="#" data-input="q" data-append="url:">url:</a>.org
        <a href="#" data-input="q" data-append="description:">desc:</a>"open source"
        <br>
        Filters:&nbsp;
        <div class="btn-group btn-group-sm" role="group" data-input="q" data-state="status" aria-label="Approval">
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:submitted' in terms else '' }}" data-status="is:submitted">Submitted</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:deferred' in terms else '' }}" data-status="is:deferred">Deferred</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:moreinformationneeded' in terms else '' }}" data-status="is:moreinformationneeded">More Info</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:approved' in terms else '' }}" data-status="is:approved">Approved</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'is:declined' in terms else '' }}" data-status="is:declined">Declined</button>
        </div>&nbsp;
        <div class="btn-group btn-group-sm" role="group" data-input="q" data-state="type" aria-label="Type">
          <button type="button" class="btn btn-secondary {{ 'active' if 'type:company' in terms else '' }}" data-type="type:company">Company</button>
          <button type="button" class="btn btn-secondary {{ 'active' if 'type:community' in terms else '' }}" data-type="type:community">Community</button>
        </div>
      </div>
    </form>
  </div>
</div>

<div class="card">
  <div class="card-body table-responsive p-0">
    <table class="table table-hover" id="organization-applications">
      <thead>
      <tr>
        <th>Account Name</th>
        <th>Organization</th>
        <th>Description</th>
        <th>Type</th>
        <th>Submitted</th>
        <th>Status</th>
      </tr>
      </thead>

      <tbody>
      {% for organization_application in organization_applications %}
      {% set information_requests = organization_application.information_requests %}
      {% set outstanding_information_requests = organization_application.information_requests|selectattr("additional", "defined")|map(attribute="additional")|selectattr("response", "undefined")|list %}
      <tr>
        <td>
          {% if information_requests %}{% if outstanding_information_requests %}  <i class="fa-solid fa-envelope text-info"></i>{% else %}  <i class="fa-solid fa-envelope-open text-green"></i><i class="fa-solid fa-reply text-green"></i>{% endif %}{% endif %}
          <a href="{{ request.route_path('admin.organization_application.detail', organization_application_id=organization_application.id) }}">{{ organization_application.name }}</a>
        </td>
        <td>
          <a href="{{ organization_application.link_url }}" rel="nofollow noopener noreferrer" target="_blank">{{ organization_application.display_name }} <i class="fa-solid fa-arrow-up-right-from-square"></i></a>
        </td>
        <td>{{ organization_application.description }}</td>
        <td>{{ organization_application.orgtype.value }}</td>
        <td>{{ organization_application.submitted }}</td>
        {% if organization_application.status == 'approved' %}
        <td><i class="fa fa-fw fa-check text-green"></i> Approved</td>
        {% elif organization_application.status == 'declined' %}
        <td><i class="fa fa-fw fa-times text-red"></i> Declined</td>
        {% elif organization_application.status == 'deferred' %}
        <td><i class="fa fa-fw fa-stopwatch"></i> Deferred</td>
        {% elif organization_application.status == 'moreinformationneeded' %}
        <td><i class="fa fa-fw fa-question text-yellow"></i> Info Needed</td>
        {% elif organization_application.status == 'submitted' %}
        <td><i class="fa fa-fw"></i> Submitted</td>
        {% else %}
        <td><i class="fa fa-fw"></i> {{ organization_application.status.value }}</td>
        {% endif %}
      </tr>
      {% endfor %}
      </tbody>
    </table>
  </div>

</div>
{% endblock content %}
